﻿// See https://aka.ms/new-console-template for more information
using EasyTool;
using EasyTool.Extension;

//Console.WriteLine("Hello, World!");

//var d = DateTimeUtil.GetFirstDayOfWeek(DateTime.Now);
//Console.WriteLine(d);

//var f = DateTime.Now.GetFirstDayOfWeek();
//Console.WriteLine(f);

//int sum = DateTimeUtil.GetDaysBetween(Convert.ToDateTime("2023-1-12 12:22:33"));
//Console.WriteLine(sum);

////获取时间戳
//long ts = TimestampUtil.GetCurrentTimestamp();
//Console.WriteLine(ts);


//// 获取当前时间戳（毫秒级）
//long timestamp = TimestampUtil.GetCurrentTimestamp();
//Console.WriteLine(timestamp);

//// 将时间戳（毫秒级）转换为 DateTime 类型
//DateTime dateTime = TimestampUtil.ConvertToDateTime(timestamp);
//Console.WriteLine(dateTime);

//// 将 DateTime 类型转换为时间戳（毫秒级）
//timestamp = TimestampUtil.ConvertToTimestamp(dateTime);
//Console.WriteLine(timestamp);

//// 获取当前时间戳（秒级）
//long timestampSeconds = TimestampUtil.GetCurrentTimestampSeconds();
//Console.WriteLine(timestampSeconds);

//// 将时间戳（秒级）转换为 DateTime 类型
//dateTime = TimestampUtil.ConvertToDateTimeSeconds(timestampSeconds);
//Console.WriteLine(dateTime);

//// 将 DateTime 类型转换为时间戳（秒级）
//timestampSeconds = TimestampUtil.ConvertToTimestampSeconds(dateTime);
//Console.WriteLine(timestampSeconds);


//string lunarDate = LunarCalendarUtil.GetLunarDate(dateTime);
//string lunarYear = LunarCalendarUtil.GetLunarYear(dateTime);
//string tianGan = LunarCalendarUtil.GetTianGan(dateTime);
//string diZhi = LunarCalendarUtil.GetDiZhi(dateTime);
//string chineseZodiac = LunarCalendarUtil.GetChineseZodiac(dateTime);
//string lunarMonth = LunarCalendarUtil.GetLunarMonth(dateTime);
//string lunarDay = LunarCalendarUtil.GetLunarDay(dateTime);

//Console.WriteLine($"公历日期：{dateTime.ToShortDateString()}");
//Console.WriteLine($"农历日期：{lunarDate}");
//Console.WriteLine($"农历年份：{lunarYear}");
//Console.WriteLine($"天干：{tianGan}");
//Console.WriteLine($"地支：{diZhi}");
//Console.WriteLine($"生肖：{chineseZodiac}");
//Console.WriteLine($"农历月份：{lunarMonth}");
//Console.WriteLine($"农历日期：{lunarDay}");

//double sums = 0;
//double dd = TimerUtil.Measure(() =>
//{
//    for (int i = 0; i < 999999999; i++)
//    {
//        sums += i;
//    }
//}).TotalMilliseconds;
//Console.WriteLine(dd);
//Console.WriteLine(sums);


// 读取文件的所有行到一个字符串数组中
//string[] lines = IoUtil.ReadAllLines("test.txt");
//Console.WriteLine("文件内容如下：");
//foreach (string line in lines)
//{
//    Console.WriteLine(line);
//}

//// 将字符串写入文件
//string text = "这是一个测试文本";
//IoUtil.WriteAllText("output.txt", text);

//// 读取指定 URL 的文本内容
//string url = "https://www.example.com/";
//string html = IoUtil.ReadUrl(url);
//Console.WriteLine("网页内容如下：");
//Console.WriteLine(html);

//// 将一个字符串转换为字节数组
//byte[] bytes = IoUtil.StringToBytes(text);

//// 读取二进制数据到一个字节数组中
//byte[] fileBytes = IoUtil.ReadAllBytes("test.bin");

//// 将字节数组写入二进制文件
//IoUtil.WriteAllBytes("output.bin", fileBytes);

//// 读取网络流到一个字符串中
//using (var stream = new System.IO.MemoryStream(bytes))
//{
//    string s = IoUtil.ReadStream(stream);
//    Console.WriteLine("内存流内容如下：");
//    Console.WriteLine(s);
//}

//List<string> ss = FileUtil.Ls("C:\\Users\\AUTO\\Desktop\\调试工具");
//foreach (string s in ss)
//{
//    Console.WriteLine(s);
//}

//WatchMonitor monitor = new WatchMonitor(@"C:\Users\AUTO\Desktop");

//monitor.FileChanged += OnFileChanged;
//monitor.FileCreated += OnFileCreated;
//monitor.FileDeleted += OnFileDeleted;
//monitor.FileMissing += OnFileMissing;

//Console.WriteLine("Press any key to stop monitoring...");
//Console.ReadKey();

//monitor.Dispose();

Tailer tailer = new Tailer(@"C:\Users\AUTO\Desktop\log.txt");

tailer.NewLine += OnNewLine;

Console.WriteLine("Press any key to stop tailing...");
Console.ReadKey();

tailer.Dispose();


Console.ReadKey();

static void OnFileChanged(object sender, FileEventArgs e)
{
    Console.WriteLine($"File '{e.FilePath}' was modified.");
}

static void OnFileCreated(object sender, FileEventArgs e)
{
    Console.WriteLine($"File '{e.FilePath}' was created.");
}

static void OnFileDeleted(object sender, FileEventArgs e)
{
    Console.WriteLine($"File '{e.FilePath}' was deleted.");
}

static void OnFileMissing(object sender, FileEventArgs e)
{
    Console.WriteLine($"File '{e.FilePath}' is missing.");
}


static void OnNewLine(object sender, string line)
{
    Console.WriteLine(line);
}